<template>
	<view class="mainbgc">
		<!-- 自定义头部 -->
		<view class="header-top-box">
			<view class="header-top fff flexbetween">
				<view class="top-image" @click="gotoBack()"></view>
				<view class="flexcenter">
					<template v-if="type==1||type==2">
						<view :class="current==1?'selecbottab tab1':'noselecbottab tab1'" @click="selectab(1)">采购历史</view>
						<view :class="current==2?'selecbottab tab2':'noselecbottab tab2'" @click="selectab(2)">退货历史</view>
					</template>
					<template v-if="type==3||type==4">
						<view :class="current==3?'selecbottab tab1':'noselecbottab tab1'" @click="selectab(3)">销售历史</view>
						<view :class="current==4?'selecbottab tab2':'noselecbottab tab2'" @click="selectab(4)">退货历史</view>
					</template>
				</view>
				<view class="konghezi"></view>
			</view>
		</view>
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.total">
				<view class="placeholderimage"></view>
			</view>
			<view class="mainpadding_top ffffff" v-for="item in list.data" :key="item.id">
				<template v-if="current==1||current==2">
					<view class="flexbetween" >
						<view class="titletext">{{item.goods.name}}</view>
						<view class="wlable radius" v-show="item.procureorder.status==10">待审核</view>
						<view class="shlable radius" v-show="item.procureorder.status==20">待入库</view>
						<view class="shlable radius" v-show="item.procureorder.status==30">已完成</view>
						<view class="hlable radius" v-show="item.procureorder.status==40">已作废</view>
					</view>
					<view class="nostrongtext margin_top2">{{item.procureorder.order_no}}</view>
				</template>
				<template v-if="current==3">
					<view class="flexbetween">
						<view class="titletext">{{item.goods.name}}</view>
						<!-- 10=待审核,20=待出库,30=待发货,40=待收货,50=已完成,60=已作废,70=已拒绝 -->
						<view class="wlable radius" v-show="item.saleorder.status==10">待审核</view>
						<view class="wlable radius" v-show="item.saleorder.status==20">待出库</view>
						<view class="wlable radius" v-show="item.saleorder.status==30">待发货</view>
						<view class="wlable radius" v-show="item.saleorder.status==40">待收货</view>
						<view class="shlable radius" v-show="item.saleorder.status==50">已完成</view>
						<view class="hlable radius" v-show="item.saleorder.status==60">已作废</view>
						<view class="hlable radius" v-show="item.saleorder.status==70">已拒绝</view>
					</view>
					<view class="nostrongtext margin_top2">{{item.saleorder.order_no}}</view>
				</template>
				<template v-if="current==4">
					<view class="flexbetween">
						<view class="titletext">{{item.goods.name}}</view>
						<!-- 10=待审核,20=待取货,30=待入库,40=已完成,50=已作废,60=已拒绝,70=拒收 -->
						<view class="wlable radius" v-show="item.salethorder.status==10">待审核</view>
						<view class="wlable radius" v-show="item.salethorder.status==20">待取货</view>
						<view class="wlable radius" v-show="item.salethorder.status==30">待入库</view>
						<view class="wlable radius" v-show="item.salethorder.status==40">已完成</view>
						<view class="hlable radius" v-show="item.salethorder.status==50">已作废</view>
						<view class="hlable radius" v-show="item.salethorder.status==60">已拒绝</view>
						<view class="hlable radius" v-show="item.salethorder.status==70">拒收</view>
					</view>
					<view class="nostrongtext margin_top2">{{item.salethorder.order_no}}</view>
				</template>
				<view class="flexbetween">
					<view class="rightbox margin_top1">
						<view class="flexleft">
							<view class="yuan"></view>
							<view class="huisetext">数量：{{item.num}}{{item.goods_unit.name}}</view>
						</view>
						<view class="flexleft">
							<view class="yuan"></view>
							<view class="huisetext">单价：￥{{item.price}}</view>
						</view>
						<view class="flexleft">
							<view class="yuan"></view>
							<view class="huisetext">总价：￥{{item.total_price}}</view>
						</view>
						<view class="flexleft">
							<view class="yuan"></view>
							<view class="huisetext">备注：{{item.notes}} </view>
						</view>
						<view class="huisetext">{{item.createtime_days_text}}（{{item.createtime_text}}）</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				current: 1,//1采购单，2采购退货单，3销售单，4退货单
				type:1,//1采购单，2采购退货单，3销售单，4退货单
				goods_id:"",
				page:1,
				list:{
					data:[]
				}
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.data));
			this.type = data.type
			if(this.type==3||this.type==4){
				this.current = 3
			}
			this.goods_id = data.goods_id
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let url = "/dhtapi/Procureorder/salesOrder"
				if(this.current==2){
					url = "/dhtapi/Procurethorder/salesOrder"
				} else if(this.current==3){
					url = "/dhtapi/Saleorder/salesOrder"
				} else if(this.current==4){
					url = "/dhtapi/Salethorder/salesthOrder"
				}
				httpRequest.request(url, 'GET', {
					page: page || 1,
					limit: 12,
					goods_id:this.goods_id
				}, false, false, true).then(res => {
					let resList = res.data.data;
					if (isPage == true) {
						_this.list.data = _this.list.data.concat(resList);
					} else {
						_this.list = res.data
						_this.list.data = resList;
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			selectab(i) {
				this.current = i
				this.init()
			},
			gotoBack() {
				uni.navigateBack(1)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.wlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		line-height: 28rpx;
		background-color: #fef7ec;
	}
	
	.shlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		line-height: 28rpx;
		background-color: #e7f9fa;
	}
	.hlable{
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ff0000;
		line-height: 28rpx;
		background-color: rgba(255, 0, 0, .1);
	}
	
	.yuan {
		width: 10rpx;
		height: 10rpx;
		margin-right: 10rpx;
		border-radius: 50%;
		background: #0BBDCB;
	}

	.huisetext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
		line-height: 42rpx;
	}

	.weishenhe {
		margin-top: 20rpx;
		width: 124rpx;
		height: 124rpx;
		background-size: 100% 100%;
		background-image: url('@/static/image/system/weishenhe.png');
	}

	.yishenhe {
		margin-top: 20rpx;
		width: 124rpx;
		height: 124rpx;
		background-size: 100% 100%;
		background-image: url('@/static/image/system/yishenhe.png');
	}
</style>
<style lang="scss" scoped>
	// 顶部自定义
	.header-top-box {
		height: 170rpx;
		width: 100%;
	}

	.konghezi {
		width: 30rpx;
		height: 30rpx;
	}

	.header-top {
		width: 100%;
		box-sizing: border-box;
		position: fixed;
		top: 0;
		left: 0;
		background-color: #fff;
		padding: 96rpx 40rpx 10rpx;
	}

	.top-image {
		margin-top: 20rpx;
		width: 20rpx;
		height: 38rpx;
		background: url('@/static/image/system/return.png') no-repeat;
		background-size: 20rpx 38rpx;
	}

	// 顶部tab
	.tab1 {
		border: 2rpx solid #0BBDCB;
		border-top-left-radius: 50rpx;
		border-bottom-left-radius: 50rpx;
		padding: 6rpx 30rpx;
	}

	.tab2 {
		border: 2rpx solid #0BBDCB;
		border-left: none;
		border-top-right-radius: 50rpx;
		border-bottom-right-radius: 50rpx;
		padding: 6rpx 30rpx;
	}

	// 选中的顶部
	.selecbottab {
		background-color: #0BBDCB;
		color: #FFFFFF;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	// 未选中的顶部
	.noselecbottab {
		background-color: #fff;
		color: #0BBDCB;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}
</style>
